import asyncio  ,time
t1=t2=time.time()
a=0
async def handle_echo(reader, writer):  
    global a,t1,t2
    
    data = await reader.read(100)  
    a+=1
    if a%30000==0:
        t2=time.time()

        print(t2-t1,a)
        t1=t2
    message = data.decode()  
    addr = writer.get_extra_info('peername')  
    # print(f"Received {message} from {addr}")  
  
    # print(f"Send: {message.upper()} to {addr}")  
    writer.write(message.upper().encode())  
    await writer.drain()  
  
    # 关闭连接  
    writer.close()  
  
async def main():  
    server = await asyncio.start_server(  
        handle_echo, '127.0.0.1', 12347)  
  
    addr = server.sockets[0].getsockname()  
    print(f'Serving on {addr}')  
  
    async with server:  
        await server.serve_forever()  
  
asyncio.run(main())